//
//  ViewController.m
//  XZBProduct
//
//  Created by xzb on 2018/6/3.
//  Copyright © 2018年 xzb. All rights reserved.
//

#import "ViewController.h"

#import <WeexSDK/WXSDKInstance.h>



@interface ViewController ()

/**instace*/
@property (nonatomic, strong) WXSDKInstance *instance;
@property (nonatomic, strong) UIView *weexView;
/**heigt*/
@property (nonatomic, assign) float weexHeight;


@end

@implementation ViewController

- (void)dealloc{
    [self.instance destroyInstance];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cyanColor];
    self.title = @"weex";
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self render];
}

- (void)render{
    _instance = [[WXSDKInstance alloc] init];
    _instance.viewController = self;
    _instance.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    [_instance renderWithURL:self.url options:@{@"bundleUrl":[self.url absoluteString]} data:nil];
    __weak typeof(self) weakSelf = self;
    _instance.onCreate = ^(UIView *view) {
        weakSelf.weexView = view;
        [weakSelf.weexView removeFromSuperview];
        weakSelf.weexView.backgroundColor = [UIColor whiteColor];
        [weakSelf.view addSubview:weakSelf.weexView];
        
    };
    
    _instance.onFailed = ^(NSError *error) {
        //process failure
        NSLog(@"render failed");
    };
    
    _instance.renderFinish = ^ (UIView *view) {
        //process renderFinish
        NSLog(@"render finish");
    };
}

@end
